package group.Filter;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器在过滤器执行之后执行,是aop的最佳实现策略
 */
public class MineInterceptor implements HandlerInterceptor {
    private Logger logger = Logger.getLogger(MineInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //在实际的处理程序运行之前
        logger.debug("请求符合拦截匹配");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        //处理程序运行后,用处不大
        logger.debug("拦截器执行方法启动之后处理！！");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        //完成完整的请求后，用处不大
        logger.debug("拦截器销毁处理！！");
    }
}
